package com.liuqi.aiagent.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;

/**
 * @author liuqi
 * @date 2025/7/28
 **/
public class DateUtil {

    public static final DateTimeFormatter Y_M_D = DateTimeFormatter.ofPattern("yyyy-MM-dd");

    public static final DateTimeFormatter Y_M = DateTimeFormatter.ofPattern("yyyy-MM");

    public static long startDayTimestamp() {
        return startDayTimestamp(LocalDate.now());
    }

    public static long startDayTimestamp(LocalDate localDate) {
        LocalDateTime localDateTime = localDate.atStartOfDay();
        return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

    public static long endDayTimestamp() {
        return endDayTimestamp(LocalDate.now());
    }

    public static long endDayTimestamp(LocalDate localDate) {
        LocalDateTime localDateTime = localDate.atTime(23, 59, 59);
        return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

    public static long startMonthTimestamp() {
        return startMonthTimestamp(LocalDate.now());
    }

    public static long startMonthTimestamp(LocalDate localDate) {
        return startDayTimestamp(firstDayOfMonth(localDate));
    }

    public static long endMonthTimestamp() {
        return endMonthTimestamp(LocalDate.now());
    }

    public static long endMonthTimestamp(LocalDate localDate) {
        return endDayTimestamp(lastDayOfMonth(localDate));
    }

    public static LocalDate firstDayOfMonth(LocalDate date) {
        return date.with(TemporalAdjusters.firstDayOfMonth());
    }

    public static LocalDate lastDayOfMonth(LocalDate date) {
        return date.with(TemporalAdjusters.lastDayOfMonth());
    }


}
